package com.xiaobai.monitor;

import com.xiaobai.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadSynchronizedEightLock {
    public static void main(String[] args) {
        Number2 number = new Number2();
        new Thread(number::a,"t1").start();
        new Thread(number::b,"t2").start();

    }
}
@Slf4j
class Number{
    public synchronized void a(){
        log.debug("1");
    }
    public synchronized void b(){
        log.debug("2");
    }
}
//先打印1马上打印2  或者是先打印2 一秒后打印1
@Slf4j
class Number2{
    public synchronized void a(){
        ThreadUtil.sleep(1);
        log.debug("1");
    }
    public synchronized void b(){
        log.debug("2");
    }
}

//312 或者 321
//32 1s 1
//23 1s 1
@Slf4j
class Number3{
    public synchronized void a(){
        ThreadUtil.sleep(1);
        log.debug("1");
    }
    public synchronized void b(){
        log.debug("2");
    }
    public  void c(){
        log.debug("3");
    }
}
